home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Typography Samples / Shift Layout ƒ / QDGX shell printing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  3.8 KB  |  146 lines  |  [TEXT/KAHL]

  1. /**\
  2. |**| =====================================================================
  3. |**|
  4. |**|    QDGX shell printing.c
  5. |**|
  6. |**|    This file contains the printing routines for
  7. |**|    the QuickDraw GX shell program.
  8. |**|
  9. |**|    ©1992-1994  Apple Computer, Inc.
  10. |**|    All rights reserved.
  11. |**|
  12. |**| =====================================================================
  13. \**/
  14.  
  15.  
  16. #include "QDGX shell.h"
  17.  
  18.  
  19. /**\
  20. |**| ---------------------------------------------------------------------
  21. |**| SetUpEditMenuRec()
  22. |**| This routine sets up an gxEditMenuRecord which references our edit
  23. |**| menu.  This structure is used by the GXJobDefaultFormatDialog and 
  24. |**| GXJobPrintDialog calls to allow cut, copy, & paste operations from
  25. |**| the dialogs.
  26. |**| ---------------------------------------------------------------------
  27. \**/
  28. void SetUpEditMenuRec (gxEditMenuRecord *edMenuRec)
  29. {
  30.  
  31.     edMenuRec->editMenuID = mEdit;
  32.     edMenuRec->cutItem = iCut;
  33.     edMenuRec->copyItem = iCopy;
  34.     edMenuRec->pasteItem = iPaste;
  35.     edMenuRec->clearItem = iClear;
  36.     edMenuRec->undoItem = iUndo;
  37. }
  38.  
  39.  
  40. /**\
  41. |**| ---------------------------------------------------------------------
  42. |**| DoFormat()
  43. |**| This routine performs GX's equivalent of the Page Setup (PrStlDialog) 
  44. |**| call of the old printing architecture.
  45. |**| ---------------------------------------------------------------------
  46. \**/
  47. OSErr DoFormat (WindowPtr wind, gxDialogResult    *result)
  48. {
  49.     OSErr                err = noErr;        
  50.     gxEditMenuRecord    edMenuRec;
  51.     gxJob                docJob;
  52.  
  53. //    If we have a non-nil WindowPtr, set up our edit menu record and handle the job
  54. //    format dialog.  Remember to check for errors.
  55.  
  56.     if ( wind != NULL )
  57.     {
  58.         docJob = GetDocJob(wind);
  59.         SetUpEditMenuRec(&edMenuRec);
  60.         *result = GXJobDefaultFormatDialog(docJob, &edMenuRec);
  61.         err = GXGetJobError(docJob);
  62.     }
  63.     
  64.     return err;
  65. }
  66.  
  67.  
  68. /**\
  69. |**| ---------------------------------------------------------------------
  70. |**| DoPrinting()
  71. |**| This routine performs GX's equivalent of the Print Job Dialog
  72. |**| (PrJobDialog) call of the old printing architecture, and then prints
  73. |**| the document if the user wants to.
  74. |**| ---------------------------------------------------------------------
  75. \**/
  76. OSErr DoPrinting (WindowPtr wind)
  77. {
  78.     OSErr            err = noErr;
  79.     gxDialogResult    result;
  80.     gxEditMenuRecord    edMenuRec;
  81.     gxJob                docJob;
  82.  
  83. //    If we have a non-nil WindowPtr, set up our edit menu record and handle the print
  84. //    job dialog.  Remember to check for errors.  If no errors occur, and the user clicks
  85. //  ok, print the window's document.
  86.  
  87.     if ( wind != NULL )
  88.     {
  89.         docJob = GetDocJob(wind);
  90.         
  91.         SetUpEditMenuRec(&edMenuRec);
  92.         result = GXJobPrintDialog(docJob, &edMenuRec);
  93.         err = GXGetJobError(docJob);
  94.                 
  95.         if ( (result == gxOKSelected) && (err == noErr) )
  96.             err = DoPrintOne(wind);
  97.     }
  98.     
  99.     return err;
  100. }
  101.  
  102.  
  103.  
  104. /**\
  105. |**| ---------------------------------------------------------------------
  106. |**| DoPrintOne()
  107. |**| This routine prints one copy of the window's document using whatever
  108. |**| job and format is currently attached to it.  (If the window were just
  109. |**| created and then the user selected Print One w/o first selecting Page
  110. |**| Setup…, the system default job and format are stored with this document.
  111. |**| ---------------------------------------------------------------------
  112. \**/
  113. OSErr DoPrintOne (WindowPtr wind)
  114. {
  115.     OSErr        err = noErr;
  116.     gxJob            docJob;
  117.     Str255        title;
  118.  
  119. //    If we have a non-nil WindowPtr, start the print job, print a page and then finish
  120. //    the job.  Since we have just a one page document, we don't bother counting pages.
  121. //    Remember to check those errors!
  122.  
  123.     if ( wind != NULL )
  124.     {
  125.         docJob = GetDocJob(wind);
  126.         GetWTitle(wind, title);
  127.     
  128.         GXStartJob(docJob, title, 1);
  129.         err = GXGetJobError(docJob);
  130.         
  131.         if ( err == noErr )
  132.         {
  133.               GXPrintPage(docJob, 1, GXGetJobFormat(docJob, 1), GetDocShape(wind));
  134.             err = GXGetJobError(docJob);
  135.         }
  136.         
  137.         GXFinishJob(docJob);
  138.         if ( err == noErr )
  139.             err = GXGetJobError(docJob);
  140.     }
  141.     return err;
  142. }
  143.  
  144.  
  145.  
  146.